package Test4;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * 4.洗牌
 *
 */
public class test {


    public static final String[] SUITS={"♠","♥","♣","♦"};

    public static void main(String[] args) {


        List<Card> cards=new ArrayList<>();


        //买牌
        System.out.println("买牌：");
        for(int i=0;i<SUITS.length;i++){
            for(int j=1;j<=13;j++){

                Card c=new Card(j,SUITS[i]);
                cards.add(c);
            }
        }

        System.out.println(cards);


        //洗牌（打乱牌）
        System.out.println("洗牌：");
        for(int i=1;i<cards.size();i++){
            Random random=new Random();

            int index=random.nextInt(i);

            swap(cards,index,i);

        }
        System.out.println(cards);

        //揭牌（三个人每人揭5张）
        System.out.println("揭牌：");

        List<Card> hand0=new ArrayList<>();
        List<Card> hand1=new ArrayList<>();
        List<Card> hand2=new ArrayList<>();
        List<Card> hands=new ArrayList<>();


        for(int i=0;i<5;i++){
            for(int j=0;j<3;j++){
               Card c=cards.remove(0);
               hands.add(c);

            }
        }
        System.out.println(hands);
    }


    public static void swap(List<Card> list,int index,int i){

        Card temp=list.get(index);

        list.set(index,list.get(i));

        list.set(i,temp);


    }
}
